<style lang="less">
  .card_style {
    height: 100%;
    width: 100%;
    overflow: hidden;
    .ivu-card-body {
      padding: 0px;
    }
  }
  .page_style {
    margin-top: 10px;
    text-align: right;
  }
  .bench_search {
    margin-bottom: 10px;
  }
  .item1{
    height: 42px;
    line-height: 40px;
  }
  .new-btn-sty {
    margin-right: 5px;
    color: #fff;
    background-color: #235CA7;
    border-color: #235CA7;
    font-weight: 500;
  }
  .ml10{
    margin-left: 10px;
  }
  .ml5{
    margin-left: 5px;
  }
  .input-width{
    width:300px;
  }
</style>

<template>
  <Card class="card_style" :bordered="false" :dis-hover="true">
    <Row class="bench_search">
      <Col span="5">
        <span>姓名：</span>
        <Input style="width:70%" v-model="params.name" />
      </Col>
      <Col span="6">
        <span>身份证号：</span>
        <Input style="width:70%" v-model="params.cardno" />
      </Col>
      <Button class="new-btn-sty" @click="searchList" style="margin-right:10px"><Icon type="ios-search" /> 搜索</Button>
      <!-- <Button class="new-btn-sty" @click="addInfo()" style="margin-right:10px"><Icon type="ios-search" /> 添加</Button> -->
    </Row>
    <Table border :columns="columns1" :data="tempDatalist">
      <template slot-scope="{ row, index }" slot="action">
        <Button type="primary" class="lyx-table-btn" size="small"  @click="showInfo(row)" ><span >详情</span> </Button>
        <!-- <Button type="primary" class="lyx-table-btn ml10" size="small"  @click="showInfo" ><span >提报</span> </Button> -->
        <!-- <Button type="primary" class="lyx-table-btn ml10" size="small"  @click="updateInfo(row)" v-if="getIsShow(row.submit_status)" ><span >修改</span> </Button> -->
        <Button type="primary" class="lyx-table-btn ml10" size="small"  @click="auditInfo(row)" v-if="getIsShow(row.submit_status)"><span >审批</span> </Button>
      </template>
    </Table>
    <Row v-if="loadData === true">
      <Col class="demo-spin-col" span="8" offset="8">
        <Spin fix>
          <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
          <div>数据正在加载</div>
        </Spin>
      </Col>
    </Row>
    <Page :total="totalnum" :current="currentPageNo" :page-size="currentPageSize" @on-change="change" class="page_style"/>
  <Modal v-model="detailModel" :title="modalTitle" width="700">
      <Form :label-width="80">
        <FormItem label="身份证号" prop="cardno">
          <Input v-model="dataInfo.cardno" class="input-width" v-bind:disabled="permiAble"></Input>
        </FormItem>
        <FormItem label="用户姓名" prop="dataInfo.name">
          <Input v-model="dataInfo.name" class="input-width" disabled></Input>
        </FormItem>
        <FormItem label="手机号码" prop="dataInfo.mobile">
          <Input v-model="dataInfo.mobile" class="input-width" disabled></Input>
        </FormItem>
        <FormItem label="申报原因" prop="reason">
          <Input v-model="dataInfo.reason" class="input-width" v-bind:disabled="permiAble"></Input>
        </FormItem>
         <FormItem label="申请金额" prop="submit_money">
          <Input :value="dataInfo.submit_money * 0.01" class="input-width" v-bind:disabled="permiAble"></Input>
        </FormItem>
        <FormItem label="备注" prop="remark">
          <Input v-model="dataInfo.remark" type="textarea" :rows="4" placeholder="请输入备注" v-bind:disabled="permiAble"></Input>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="error" @click="detailModel=false">取消</Button>
      </div>
    </Modal>
  <Modal v-model="auditModel" :title="'审批意见'" width="700">
      <Form :label-width="80">
        <FormItem label="审批状态" prop="status">
          <Select v-model="auditData.status" style="width:300px">
            <Option value="0">通过</Option>
            <Option value="1">不通过</Option>
          </Select>
        </FormItem>
        <FormItem label="审批意见" prop="result">
          <Input v-model="auditData.result" type="textarea" :rows="4" placeholder="请输入审批意见"></Input>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="error" @click="auditModel=false">取消</Button>
        <Button type="success" @click="submitOpinion()">保存</Button>
      </div>
    </Modal>
  </Card>
</template>

<script>
import { findCapitalSubmitList, addCapitalSubmit, getUserInfo, updateCapitalSubmit, addCapitalSubmitCheck } from '@/api/capitalOrder'
export default {
  name: 'businessCheck',
  data () {
    return {
      stateList: [
        {
          value: '2',
          label: '区县审核'
        },
        {
          value: '3',
          label: '市区审核'
        },
        {
          value: '4',
          label: '市财政审核'
        },
        {
          value: '5',
          label: '审核通过'
        },
        {
          value: '20',
          label: '区县审核不通过'
        },
        {
          value: '30',
          label: '市区审核不通过'
        },
        {
          value: '40',
          label: '市财政审核不通过'
        }
      ],
      columns1: [
        { title: '序号', type: 'index', width: 70, align: 'center' },
        { title: '用户姓名', key: 'name', width: 150, align: 'center' },
        { title: '身份证号', key: 'cardno', width: 180, align: 'center' },
        { title: '手机号', key: 'mobile', width: 120, align: 'center' },
        { title: '申请批次', key: 'batch', width: 150, align: 'center' },
        { title: '申报原因', key: 'reason', width: 150, align: 'center' },
        { title: '提报时间', key: 'submit_time', width: 150, align: 'center' },
        {
          title: '申请金额',
          key: 'submit_money',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.submit_money * 0.01)
          }
        },
        {
          title: '当前状态',
          key: 'state',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h('span', this.getState(params.row.submit_status))
          }
        },
        {
          title: '操作',
          slot: 'action',
          width: 150,
          align: 'center'
        }
      ],
      tempDatalist: [],
      params: { pageNo: 1, pageSize: 10 },
      company_code: this.$store.state.user.severUserInfo.company_code,
      loadData: false, // true加载
      currentPageSize: 10,
      currentPageNo: 1,
      totalnum: 0,
      dataInfo: { },
      auditData: {},
      auditModel: false,
      detailModel: false,
      permiAble: false,
      modalTitle: ''
    }
  },
  methods: {
    getState (value) {
      let name = ''
      this.stateList.forEach(element => {
        if (element.value === value) {
          name = element.label
          return name
        }
      })
      return name
    },
    init (params) {
      this.tempDatalist = []
      findCapitalSubmitList(params).then(res => {
        if (res.data.errcode === 0) {
          this.tempDatalist = res.data.data.results
          this.totalnum = res.data.data.totalRecord
          this.loadData = false
        } else {
          this.loadData = true
          this.$Notice.error({ title: '获取数据失败', desc: res.data.errmsg })
        }
      })
    },
    searchList () {
      this.params.pageNo = '1'
      this.init(this.params)
    },
    change (pageNo) {
      this.params.pageNo = pageNo
      this.loadData = true
      this.init(this.params)
    },
    getUser () {
      let param = {
        cardno: this.dataInfo.cardno
      }
      getUserInfo(param).then(res => {
        if (res.data.errcode === 0) {
          this.dataInfo = {}
          this.dataInfo.name = res.data.data.name
          this.dataInfo.cardno = res.data.data.cardno
          this.dataInfo.mobile = res.data.data.mobile
        } else {
          this.$Notice.error({ title: '获取数据失败', desc: res.data.errmsg })
        }
      })
    },
    showInfo (row) {
      this.modalTitle = '统发详情'
      this.permiAble = true
      this.detailModel = true
      this.dataInfo = row
    },
    addInfo () {
      this.dataInfo = {}
      this.permiAble = false
      this.detailModel = true
      this.modalTitle = '申请发放金额'
    },
    updateInfo (row) {
      this.data = {}
      this.permiAble = false
      this.detailModel = true
      this.modalTitle = '修改申请'
      if (row !== '') {
        this.dataInfo = row
      }
    },
    submitCapital (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.dataInfo.company_code = this.company_code
          if (this.dataInfo.id === '' || this.dataInfo.id === undefined) {
            this.createCapitalSubmit(this.dataInfo)
          } else {
            this.updateSubmit(this.dataInfo)
          }
          this.permiAble = false
        } else {
          this.$Modal.error({
            title: '请完善信息'
          })
        }
      })
    },
    createCapitalSubmit (params) {
      addCapitalSubmit(params).then(res => {
        if (res.data.errcode === 0) {
          this.$Modal.success({
            title: '添加成功'
          })
          this.detailModel = false
          this.params.pageNo = '1'
          this.init(this.params)
        } else {
          this.$Modal.error({ title: '添加失败', desc: res.data.errmsg })
        }
      })
    },
    updateSubmit (params) {
      updateCapitalSubmit(params).then(res => {
        if (res.data.errcode === 0) {
          this.$Modal.success({
            title: '修改成功'
          })
          this.detailModel = false
          this.init(this.params)
        } else {
          this.$Modal.error({ title: '修改失败', desc: res.data.errmsg })
        }
      })
    },
    auditInfo (row) {
      this.auditData = {}
      this.auditModel = true
      this.auditData.submit_id = row.id
      this.auditData.batch = row.batch
      this.auditData.company_code = this.company_code
      this.auditData.submit_status = row.submit_status
    },
    submitOpinion () {
      if (this.auditData.status === '' || this.auditData.status === undefined) {
        this.$Modal.error({
          title: '请选择审批状态'
        })
        return
      }
      if (this.auditData.status === '1') {
        if (this.auditData.result === '' || this.auditData.result === undefined) {
          this.$Modal.error({
            title: '请输入审批意见'
          })
          return
        }
      }
      this.auditData.company_code = this.company_code
      addCapitalSubmitCheck(this.auditData).then(res => {
        if (res.data.errcode === 0) {
          let param = {
            id: this.auditData.submit_id,
            submit_status: this.getStatus(this.auditData.status, this.auditData.submit_status)
          }
          updateCapitalSubmit(param).then(ret => {
            if (ret.data.errcode === 0) {
              this.$Modal.success({
                title: '审批成功'
              })
              this.init(this.params)
            } else {
              this.$Modal.error({ title: '审批修改失败', desc: ret.data.errmsg })
            }
          })
          this.auditModel = false
          this.init(this.params)
        } else {
          this.$Modal.error({ title: '审批失败', desc: res.data.errmsg })
        }
      })
    },
    getStatus (status, submit_status) {
      let code = ''
      if (status === '0') {
        switch (submit_status) {
          case '2': code = '3'
            break
          case '3': code = '4'
            break
          case '4': code = '5'
        }
      } else if (status === '1') {
        switch (submit_status) {
          case '2': code = '20'
            break
          case '3': code = '30'
            break
          case '4': code = '40'
            break
        }
      }
      return code
    },
    getIsShow (status) {
      if (status === '5' || status === '20' || status === '30' || status === '50') {
        return false
      }
      return true
    }
  },
  mounted () {
    this.init(this.params)
  }
}
</script>
